import time
import requests

def chat_with_kimi(api_key, prompt):
    url = "https://api.moonshot.cn/v1/chat/completions"
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    data = {
        "model": "moonshot-v1-8k",
        "messages": [{"role": "user", "content": prompt}],
        "temperature": 0.3
    }
    response = requests.post(url, headers=headers, json=data)
    return response.json()

def main():
    # kimi 的api_key
    api_key = "sk-pDB1uv93mVtDQBETpWgxxh4pRrpUsj8Jmqh7UmfdzfvYUsKv"
    prompt = "你好"
    while True:
        response = chat_with_kimi(api_key, prompt)
        print(response["choices"][0]["message"]["content"])
        # 在这里设置下一次的提示词
        prompt = "今天是星期几？"
        time.sleep(2)  # 等待2秒后继续

if __name__ == "__main__":
    main()